package com.example.matchingjava.controller;


import com.example.matchingjava.ThrowData.Result;
import com.example.matchingjava.domain.MatchingMsg;
import com.example.matchingjava.service.impl.MatchingServiceImpl;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/admin")
public class MatchingController {
    @Resource
    private MatchingServiceImpl matchingService;

    @RequestMapping("/add")
    public Result add(@RequestBody MatchingMsg matchingMsg){
        Result result = new Result();

        Boolean data = matchingService.saveMatching(matchingMsg);
        result.setData(data);
        result.setMsg("成功");
        result.setSuccess(true);
        return result;
    }

    @RequestMapping(value = "/delete")
    public Result deleteMsg(@RequestBody MatchingMsg matchingMsg){
        Result result = new Result();

        Boolean data = matchingService.removeByIdMatching(matchingMsg.getId());
        result.setData(data);
        result.setMsg("成功");
        result.setSuccess(true);
        return result;
    }

    @RequestMapping(value = "/updata")
    public Result updata(@RequestBody MatchingMsg matchingMsg){
        Result result = new Result();
        Boolean data = matchingService.updateMatching(matchingMsg);

        result.setData(data);
        result.setMsg("成功");
        result.setSuccess(true);
        return result;
    }

    @RequestMapping(value = "/search")
    public Result search(@RequestBody MatchingMsg matchingMsg){
        Result result = new Result();

        List<MatchingMsg> data = matchingService.listMatching();
        result.setData(data);
        result.setMsg("成功");
        result.setSuccess(true);
        return result;
    }
}
